package com.google.code.nexttraffic.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.google.code.nexttraffic.dao.TimetableDao;
import com.google.code.nexttraffic.dao.support.SimpleJdbcDaoSupport;
import com.google.code.nexttraffic.web.model.Terminal_Temp;
import com.google.code.nexttraffic.web.model.Timetable;

public class TimetableDaoJdbcImpl implements TimetableDao {

	private static SimpleJdbcDaoSupport dbConn;
	private static TimetableDaoJdbcImpl daoJdbcImpl;
	
	private TimetableDaoJdbcImpl() {
	};

	public static TimetableDaoJdbcImpl getInstance() {

		if (daoJdbcImpl == null) {
			dbConn = SimpleJdbcDaoSupport.getInstance();
			daoJdbcImpl = new TimetableDaoJdbcImpl();
		}

		return daoJdbcImpl;
	}
	
	
	@Override
	public int getLastNumIncrement() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Timetable getTimetable(Integer timetableIdNum) {
		
		Connection conn = dbConn.getCon();
		
		Timetable timetable=null;

		try {
			Statement stmt = conn.createStatement();
			
			String query = "SELECT timetableid,"+
						           "distance,"+
						           "timerequired,"+
						           "starttime,"+
						           "buskind,"+
						           "road,"+
						           "buscompany,"+
						           "etc,"+
						           "startterminal,"+
						           "arrivalteminal"+
						      "FROM TIMETABLE"+
						      "WHERE timetableid="+timetableIdNum;
			
			ResultSet rs = stmt.executeQuery(query);

			if (rs.next()) {

				timetable=new Timetable();
				
				timetable.setTimetableid(rs.getInt("TimetableId"));
				
				timetable.setStartTime(rs.getString("StartTime"));
				timetable.setStartTerminal(rs.getInt("StartTerminal"));
				timetable.setArrivalTerminal(rs.getInt("ArrivalTerminal"));
				
				timetable.setDistance(rs.getString("Distance"));
				timetable.setEtc(rs.getString("ETC"));
				timetable.setRoad(rs.getString("ROAD"));
				timetable.setBuscompany(rs.getString("ArrivalTeminal"));
				timetable.setTimerequied(rs.getString("Timerequired"));
				
			}

			rs.close();
			stmt.close();
			conn.close();

		} catch (SQLException e) {
			e.printStackTrace();
		}

		
		return null;
	}

	@Override
	public int insertTimetable(Timetable timetable) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int deleteTimetable(int timetableid) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<Timetable> getListTimetable() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Timetable> getListTimetable(int terminalid) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int modifyTimetable(Timetable timetable) {
		// TODO Auto-generated method stub
		return 0;
	}



}
